USE [GESTION2]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0008_CALCULA_VALOR_CUOTA]    Script Date: 11/22/2011 15:34:24 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_D0008_CALCULA_VALOR_CUOTA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_D0008_CALCULA_VALOR_CUOTA]
GO

USE [GESTION2]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0008_CALCULA_VALOR_CUOTA]    Script Date: 11/22/2011 15:34:24 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<JJ>
-- Create date: <01/08/2011>
-- Description:	<CALCULA VALOR CUOTA>
-- =============================================
CREATE PROCEDURE [dbo].[WASP_D0008_CALCULA_VALOR_CUOTA]

AS
BEGIN
select  
	a.ppsuc as aosuc, a.ppcta as aocta, a.ppoper as aooper, count(a.ppoper) as cuotas
into as_cuotas_spt_temp
from  
	fsd601 a (nolock), 
	fsd010 b (nolock)
where 	
	a.Ppsbop = 0 and 
	a.ppoper <> 999999999 and 
	a.ppcta <> 999999999 and 
	a.d601co = 'S' and 
	--aostat <> 99 and 
	b.aosuc = a.ppsuc and 
	b.aocta = a.ppcta and 
	b.aooper = a.ppoper and 
	b.aosbop = 0 and 
	b.aocta <> 999999999 and 
	b.aooper <> 999999999  and
	NOT EXISTS(
	SELECT *
        FROM as_desistidos as anu
        WHERE b.aocta = anu.hcta and
              b.aooper = anu.hoper and
              b.aosuc = anu.hsucur)
group by
	a.ppsuc, a.ppcta, a.ppoper
END

GO

